<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ page import="com.c0nflict.server.*, com.mysql.jdbc.Statement, com.mysql.jdbc.ResultSet" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ include file="admin_header.jspf" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>c0nflict: Active Players</title>
</head>
<body>
<%
Database db = tm.db;

if (db == null)
	out.println("Unable to connect to database!");
else {
	Statement stmt = (Statement)db.getConnection().createStatement();
	String query = 
		"select d.user_id Id, d.username Name, d.user_email Email, u.admin_level Admin, u.elo ELO, p.games Games, " +
		"s.first_login, s.last_login " +
		"from jforum_users d, dq_user u, " +
		"(select user_id, count(game_id) games from dq_game_stats_players " +
				" where death_time > date_add(curdate(), interval -28 day) group by 1) p, " +
		"(select user_id, min(start_time) first_login, max(start_time) last_login from dq_session_log group by 1) s " + 
		"where u.user_id = d.user_id and p.user_id = u.user_id and s.user_id = u.user_id and p.games > 0 order by d.user_id"; 
	ResultSet rs = (ResultSet)stmt.executeQuery(query);
	
	rs.last();
	
	int recordCount = rs.getRow();
	
	rs.beforeFirst();
%>
<center><h3 style="color: #ccc;"><b><%= tm.WATCHDOG.toString() %></b></h3></center>

<center><font size="5" color="white" face="verdana"><b><a name="players">Active Players (last 4 weeks)</a></b></font></center>
<div class="dbdataContainer">
<font size="2" color="white" face="verdana"><%= recordCount %> records found:</font>
<table class="sortable" cellpadding="4" cellspacing="0">
<thead>
<tr>
	<th>ID</th>
	<th>Name</th>
	<th>Email</th>
	<th>ELO</th>
	<th>Games<br/>(last 4 weeks)</th>
	<th>Admin</th>
	<th>First Login</th>
	<th>Last Login</th>
</tr>
</thead>
<tfoot>
<tr><td colspan="0">Active Players in database as of <%= tm.WATCHDOG.toString() %></td></tr>
</tfoot>
<tbody>
	<% while (rs.next()) { %>
<tr <% if (rs.getRow() % 2 == 1) { %> bgcolor="#222" <% } %>>
	<td><%= rs.getInt("Id") %></td>
	<td><%= rs.getString("Name") %></td>
	<td><%= rs.getString("Email") %></td>
	<td><%= rs.getInt("ELO") %></td>
	<td><%= rs.getInt("Games") %></td>
	<td><%= rs.getInt("Admin") %></td>
	<td><%= rs.getString("first_login") %></td>
	<td><%= rs.getString("last_login") %></td>
</tr>
	<% } %>
</tbody>
</table>
</div>
<% } %>
<%@ include file="admin_footer.jspf" %>
</body>
</html>